<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/plateform/include/common-base.jsp"%>
  <title>机构管理员管理</title>
  <!--jquery.qrcode 二维码 -->
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
   
</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

<!-- top start -->
<%@include file="/common/plateform/top.jsp" %>
<!-- top end -->
<!-- left start -->
<%@include file="left-account.jsp" %>
  <!-- left end-->

  <div class="content-wrapper">
  
   <script>
  var add_url = "${ctx}/res/uct/admin/saveUser";
  var del_url = "${ctx}/res/uct/admin/delUser";
  var view_url = "${ctx}/trans/info/userInfo";
  //var org_url = "${ctx}/uct/org/org!initOrg.action";
  var org_url = "${ctx}/trans/list/orgInit";
  var dept_url = "${ctx}/trans/list/deptInit";//?orgId=${item.orgId}
  var id;
  </script>
  <!--  
		<ol class="breadcrumb bgblue">
			<li>
				<span class="label label-danger font14" >机构与用户管理 / 用户管理</span>
			</li>
		</ol>
	-->	
    <!-- Main start -->

<section class="content">
      <div class="row">
        <div class="col-xs-12">
        
        <!-- 机构搜索 start -->
           <div class="box box-info">
             <!--搜索title  start --> 
	          <div class="box-header with-border">
                 <h3 class="box-title"><i class="fa fa-search"></i> 机构管理员搜索</h3>
                 <div class="box-tools pull-right">
	                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
	                </button>
	                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                 </div>
              </div>
            <!--搜索title  end --> 
            <div class="box-body">
			  <form id="searchFrom" class="form-horizontal">
				<input type="hidden" name="userStatus" value="1"/>
				<input type="hidden" name="doCode" value="userList"/>
				<input type="hidden" name="userType" value="manager"/>
				<c:if test="${loginUser.sysFlag !='1'}">
				   <input type="hidden" name="orgId" value="${loginUser.dataOrgIds }${loginUser.orgId }"/>
				</c:if>
				<div class="form-group">
					<div class="col-sm-3 text_r"><label class="control-label">用户账号：</label></div>
					<div class="col-sm-2">
						 <input class="form-control clean" name="userEname" id="userEname" value="" type="text">
					</div>
					<div class="col-sm-2 text_r"><label class="control-label">用户姓名：</label></div>
					<div class="col-sm-2">
						 <input class="form-control clean" name="userCname" id="userCname" value="" type="text">
					</div>
				</div>
				<center>
				   <div class="box-footer clearfix">
				       <button type="button" class="btn btn-success" onclick="getTableData();"><i class="fa fa-search"></i> 查询</button>&nbsp;
				       <button type="button" class="btn btn-warning" onclick="mytools.cleanData('#searchFrom');">重置 </button>
				   </div>
				</center>
			  </form>
            </div>
	     </div>
         <!-- 机构搜索 end -->
        
      <div class="box box-success">
            <div class="box-header with-border">
                 <h3 class="box-title"><i class="fa fa-table"></i>  机构管理员管理　　　
					<c:if test="${loginUser.sysFlag =='1'}">
						<button class="btn btn-success" type="button" onclick="toAdd();">增加机构管理员</button>
					</c:if>
				        <button class="btn btn-danger" type="button" onclick="del();">删除</button>
				        <button class="btn btn-info" type="button" onclick="toEdit();">修改</button>
				        <button class="btn btn-warning" type="button" onclick="refresh();">刷新</button>
				        <button class="btn btn-info" type="button" onclick="toAct();">用户权限</button>	
                 </h3>
                 <div class="box-tools pull-right">
	                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
	                </button>
	                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                 </div>
              </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example" class="table table-bordered table-hover" >
                <thead>
                <tr>
                  <th>用户账号</th><th>用户姓名</th>
                  <th>所属机构</th><th>所属部门</th>
                  <th>用户类型</th>
                  <th>用户类别</th><th>手机</th><th>状态</th><th>创建时间</th>
                </tr>
                </thead><tbody id="myList"></tbody>
              </table>
         	    <center><ul id="pageList"></ul></center>
            </div>
          </div>
        </div>
      </div>
    </section>
    <!-- Main end -->
    
<div class="modal fade" id="my_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
				<div class="modal-content" id="user-editManager"></div>
				<!-- /.modal-content -->
			</div>		
</div>  
  
	<div class="modal fade" id="act_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog" style="width:900px;">
					<div class="modal-content" id="user-acts"></div>
					</div>
					<!-- /.modal-content -->
	</div>	
    
    
    <script type="text/template" id="dataList">
	  		<? for ( var i = 0; i < rows.length; i++) {?>
				<tr>
					<td style="display:none;"><?=rows[i].userId?></td>
					<td><?=rows[i].userEname?></td>
					<td><?=rows[i].userCname?></td>
					<td><?=orgData[rows[i].orgEname]?></td>
					<td><?=rows[i].deptName?></td>
					<td><?=userTypeData[rows[i].userType]?></td>
					<td>
						<?if(rows[i].delStatus=='1'){?>平台管理员<?}?>
						<?if(rows[i].delStatus=='0'){?>机构用户<?}?>
						<?if(rows[i].delStatus=='2'){?>机构管理员<?}?>
						<?if(rows[i].delStatus=='3'){?>系统管理员<?}?>
					</td>
					<td><?=rows[i].mobile?></td>
					<td>
						<?if(rows[i].userStatus=='1'){?>
								启用
						<?}?>
						<?if(rows[i].userStatus=='0'){?>
								停用
						<?}?>
					</td>
					<td><?=getFormatDateByLong(rows[i].createTime,'yyyy-MM-dd hh:mm:ss')?></td>
				</tr>
     		<?}?>
	</script>
    
    
   <script>
var clickMenu= 'org-user-list';
var userCname;
var sysUser='${loginUser.sysFlag}';
var userTypeData={};
var userStatusData={};
var userSexData={};
var orgData = {};
$(function () {
	$("#user-editManager").load("${ctx}/template/uct/user-edit.html",function(){//loadItems(code,cname);
		//DictUtil.getDictExtList("#userType", dictUrl, {cateEname:"userType"});//用户类型
		//DictUtil.getRadioList("#userSexDiv","userSex", dictUrl,{cateEname:"userSex"});//用户性别
		userTypeData = DictUtil.getCommonDictData("select","#userType","userType","doCode=dictItemList&cateEname=userType","{value:'itemValue',text:'itemText'}","");
		userSexData = DictUtil.getCommonDictData("radio","#userSexDiv","userSex","doCode=dictItemList&cateEname=userSex","{value:'itemValue',text:'itemText'}","M");
		initOrg("orgId");

        getTableData();

	});
	$('#example tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	            //$(this).removeClass('selected');
	        } else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	     id = $('tr.selected td').eq(0).html();
	     userCname = $('tr.selected td').eq(1).html();
	   //  console.log($('tr.selected td').eq(1).html())
	} );
  });
//设置模态框隐藏事件钩子  
$( '#my_modal' ).on( 'hide.bs.modal' ,function(e){  
	mytools.cleanData("#userForm");
}); 

//设置模态框隐藏事件钩子  
$( '#my_modal' ).on( 'show.bs.modal' ,function(e){  
	$.ajax({ 
		type:'get',
		async:false,
		url:'${ctx}/sendPage/token?token=true',
	    dataType:'json', 
	    success: function(myData){
			 $('#formToken').val(myData);
	  	}
	});	

}); 

function getTableData(){
	deleteAllRow('example');
	$("#act-userId").val(id);
	$.ajax({
		   type:'get',
		   url:common_list_url,//user_search_url,
		   data:$('#searchFrom').serialize()+getCurrentPage(common_list_url+"?"+$('#searchFrom').serialize(),10),
		   dataType:'json',
		   success: function(myData){
			var data = baidu.template('dataList',eval(myData));  
			$("#myList").html(data);
			  var option= {
					   ele:$("#pageList")[0],
					   total:myData.total,
					   fn:getTableData,
					   url:common_list_url+"?"+$('#searchFrom').serialize()
				   }
			generatePages(option);
		   }
		});	
  }
  
function getRoleListData(){
	deleteAllRow('roleList');
	$("#act-userId").val(id);
	$.ajax({ type:'post', url:'${ctx}/res/uct/admin/userRoleData?userId='+id,
		   data:$('#actFrom').serialize(), dataType:'json',
		   success: function(myData){
			var data = baidu.template('roleListData',eval(myData));  
			$("#roleList").html(data);
		   }
	 });	
  } 

function deleteAllRow(tableId){
	var tb = document.getElementById(tableId);
	if(tb){
	     var rowNum=tb.rows.length;
	     for (i=1;i<rowNum;i++){
	         tb.deleteRow(i);
	         rowNum=rowNum-1;
	         i=i-1;
	     }
     }
}
function toAdd(){
	$("#if-sysFlag").show();
	$("#if_update_pass_div").hide();
	$("#edit_user_pass").show();
	
	$("#btn_add").removeClass("hidden");
	$("#btn_edit").addClass("hidden");
    $("#userFormData").find("input[name='userEname']").prop("readonly",false);
	mytools.cleanData("#userForm");
	$('#my_modal').modal('show');

    DictUtil.checkSelectDict("#userType","manager");
    $("#userType").attr("readonly",true);
    $("#userEname").attr("readonly",false);
    $("#delStatus").val("2");

}

function getObjInfo(myData){
	 FormUtil.loadView("", myData);
	 $('#my_modal').modal('show');
}
function toAct(){
	$('#table1 tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	        } else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	} );
	//getRoleListData();
	$("#user-acts").load("${ctx}/template/uct/user-acts.html",function(){
	    getRoleListData();});
	$('#act_modal').modal('show');
}

function cannel(modalId){
	$('#'+modalId).modal('hide');
}

function initOrg(selectId){
	$("#"+selectId).html("");
	$("#"+selectId).append("<option value=''>--请选择--</option>");
	$.ajax({url: org_url+'?orgIds=${loginUser.dataOrgIds }${loginUser.orgId }',  async:false,
        type: "get",dataType: "text",
        success: function(data){
        	if(data){
	        	var obj = $.parseJSON(data);
				for(var i = 0; i < obj.length; i++){
					$("#"+selectId).append("<option value='"+obj[i].orgId+"'>"+obj[i].orgCname+"</option>");
					orgData[obj[i].orgEname]=obj[i].orgCname;
				}
        	}
        }
    });
}

//value:orgId
function initDept(selectId,value){
	//alert(selectId+"|"+value);
	$("#"+selectId).html("");
	$("#"+selectId).append("<option value=''>--请选择--</option>");
	if(sysUser=="0"){
		$("#"+selectId).append("<option value='${loginUser.deptId}'>${loginUser.deptCname}</option>");
	}else{
		$.ajax({ url: dept_url, data:{'orgId':value},
	        async:false,type: "get", dataType: "text",
	        success: function(data){
	        	var obj = $.parseJSON(data);
				for(var i = 0; i < obj.length; i++){
					$("#"+selectId).append("<option value='"+obj[i].deptId+"'>"+obj[i].deptCname+"</option>");
				}
	        }
	    });
	}
}

function refresh(){
	getTableData();
}

</script> 
    
    
  </div>
  
	
</div>    
      <%@include file="/common/plateform/foot.jsp" %>
  
</body>


</html>
